package com.dfrz.bookstore.service.impl;

import com.dfrz.bookstore.dao.impl.IdeaDaoImpl;
import com.dfrz.bookstore.entry.Idea;
import com.dfrz.bookstore.service.IdeaService;

import javax.swing.*;
import java.util.List;

/**
 * 类功能描述:
 *
 * @Author keyan
 * @Date 2021/5/22 13:51
 */
public class IdeaServiceImpl implements IdeaService {
    IdeaDaoImpl ideaDao = new IdeaDaoImpl();
    @Override
    public void updateIdea(Idea idea) {
        boolean flag = ideaDao.updateByObj(idea);
        if (flag){
            System.out.println("更新成功 刷新窗体");
        }else {
            System.out.println("更新失败,id不存在");
        }
    }

    @Override
    public void insertIdea(Idea idea) {
        boolean flag = ideaDao.insert(idea);
        if (flag){
            JOptionPane.showMessageDialog(null,"意见提交成功");
        }else {
            JOptionPane.showMessageDialog(null,"意见提交失败");
        }
    }

    @Override
    public void delectIdea(int id) {
        boolean flag = ideaDao.deleteObjById(id);
        if (flag){
            System.out.println("删除成功 刷新窗体");
        }else {
            System.out.println("删除失败,id无效");
        }
    }

    @Override
    public List<Idea> findIdeaByIdea(Idea idea) {
        List<Idea> ideaList = ideaDao.findObjByObj(idea);
        return ideaList;
    }

    @Override
    public List<Idea> findIdeaByPage(Idea idea, int pageNum, int pageSize) {
        List<Idea> ideaList = ideaDao.findObjByPage(idea,pageNum,pageSize);
        return ideaList;
    }
}
